<template>
  <CommentPost :is-delete="false" :data-source="dataSource.values as Post[]" />
</template>

<script setup lang="ts">
import CommentPost from "@/components/CommentPost.vue";
import { PostControllerService } from "../../../generated";
import { onMounted, reactive, ref } from "vue";
import { Post } from "../../../generated";
import { Message } from "@arco-design/web-vue";
import moment from "moment/moment";

const dataSource = reactive([]) as Post[];
const searchParams = {
  current: 1,
  pageSize: 10,
};
const loads = async () => {
  const res = await PostControllerService.listMyPostVoByPageUsingPost({
    ...searchParams,
  });
  if (res.code === 0) {
    Message.success("获取信息成功");
    // 获取用户信息
    for (const item of res.data.records) {
      item.userName = item.user.userName;
      item.userAvatar = item.user.userAvatar;
      item.createTime = moment(item.createTime).format("YYYY-MM-DD HH:mm:ss");
      item.isShowMoment = false;
      item.isDelete = false;
    }
    // 更新评论区内容
    dataSource.values = res.data.records;
  } else {
    Message.error("获取信息失败" + res.message);
  }
};
onMounted(() => {
  loads();
});
</script>

<style scoped></style>
